﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Umbrella.Net.Contracts;

namespace UmbrellaTest
{
    /// <summary>
    /// Summary description for UmbrellaNetTest
    /// </summary>
    [TestClass]
    public class UmbrellaNetTest
    {
        public UmbrellaNetTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        private UmbrellaServiceClientFactory _factory;

        [TestInitialize]
        public void CreateFactory()
        {
            _factory = new UmbrellaServiceClientFactory();
        }

        [TestMethod]
        public void GetLatestRelease()
        {
            var lvq = new LatestVersionQuery()
            {
                CurrentVersionId = 0,
                InstanceId = Guid.NewGuid(),
                StatiToQuery = ReleaseStatus.All,
            };

            var lr = _factory.CreateChannel().GetLatestVersion(lvq);

            Assert.IsNotNull(lr);

            Console.WriteLine("Version: " + lr.VersionString);
            Console.WriteLine("SharePoint: " + lr.SharePointVersionString);
        }

        [TestMethod]
        public void LoadLanguages()
        {
            var lngs = _factory.CreateChannel().GetSharePointLanguages();

            Assert.IsTrue(lngs.Count() > 0);
            
            foreach (var l in lngs)
            {
                Console.WriteLine(l.Title);
            }
        }

        [TestMethod]
        public void LoadInstallationPackages()
        {
            var lngs = _factory.CreateChannel().GetSharePointInstallationFiles(int.MaxValue);

            Assert.IsTrue(lngs.Count() > 0);

            foreach (var l in lngs)
            {
                Console.WriteLine(l.LanguageLCID + ": " + l.ZipDownloadUrl);
            }
        }
    }
}
